import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_layout/bloc/my/my_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class My extends StatelessWidget {
  const My({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(create: (context) => MyBloc(), child: MyView());
  }
}

class MyView extends StatelessWidget {
  const MyView({super.key});

  @override
  Widget build(BuildContext context) {
    final myBloc = BlocProvider.of<MyBloc>(context);

    return BlocBuilder<MyBloc, MyState>(builder: (context, state) {
      return SizedBox(
          width: double.infinity,
          child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text("数字加载发功能页,快速熟悉flutter_bloc相关操作"),
                SizedBox(height: 10.h),
                Text('${state.title}: ${state.count}'),
                TextButton(
                  onPressed: () {
                    myBloc.add(MyUpdateCount(init: 2));
                  },
                  child: Text('add'),
                ),
                ElevatedButton(
                  onPressed: () {
                    myBloc.add(MyUpdateCount(init: 3, type: "prev"));
                  },
                  child: Text('prev'),
                ),
              ]));
    });
  }
}
